package cn.sample.moreitems.util;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

import java.io.IOException;

public class Utils {

    public static void animateFlyTo(Entity item, Vec3 target) {
        Level level = item.level();
        if (level.isClientSide) return;

        Vec3 cur = item.position();
        Vec3 diff = target.subtract(cur);
        double diffLength = diff.length();

        Vec3 scale = diff.normalize().scale(Math.min(0.3, diffLength));

        if (diff.lengthSqr() < 0.2) return;     // 已到


        item.setDeltaMovement(scale);
        item.hurtMarked = true;                  // 强制同步
    }
}
